<?php
include "Class/EasyMySQL.php";

    $mysql = new EasyMySQL();
    if(!$mysql->Connect())  return;

    $method = $_REQUEST["Method"];
    $data = file_get_contents('php://input', 'r');
    $data = iconv("GB2312", "UTF-8//IGNORE", $data);

    if($method == "Select")
    {
        $Names =  "USer.UID AS UID,User.Name AS Name,User.Username AS Username,User.Password AS Password,
                USer.OfficeUID AS OfficeUID,Office.Name AS OfficeName,
                Office.CityUID AS CityUID,City.Name AS CityName,
                City.ProvinceUID AS ProvinceUID,Province.Name AS ProvinceName,  
                User.Integral AS Integral,
                USer.DefAddressUID AS DefAddressUID,
                Device.Address AS Address,
                GROUP_CONCAT(Coupon.Name) AS Coupon";

        $mysql->SELECT("USer", $Names)
            ->LEFTJOIN("Office", "User.OfficeUID=Office.UID")
            ->LEFTJOIN("City", "Office.CityUID=City.UID")
            ->LEFTJOIN("Province", "City.ProvinceUID=Province.UID")
            ->LEFTJOIN("UserAddress", "USer.DefAddressUID=UserAddress.UID")
            ->LEFTJOIN("Device", "UserAddress.DeviceUID=Device.UID")
            ->LEFTJOIN("UserCoupon", "User.UID=UserCoupon.UserUID")
            ->LEFTJOIN("Coupon", "UserCoupon.CouponUID=Coupon.UID")
            ->WhereSelect("User.OfficeUID=".$data)
            ->GroupBy("USer.UID")
            ->QuerySelect();
    }
    else if($method == "Insert")
    {
        $mysql->Insert("User")->InsertColumns("UID,Name,Username,Password,OfficeUID,Integral,DefAddressUID")->InsertValues($data, 7)->QueryInsert();
    }
    else if($method == "Update")
    {
        $array = explode("#", $data);
        $mysql->Update("User")->UpdateSet($array[0])->WhereUpdate("UID=".$array[1])->Query();
    }
    else if($method == "Delete")
    {
        $mysql->Delete("User")->WhereDelete("UID", $data)->Query();
    }

    $mysql->Close();
?>